<template>
	<el-select v-model="selectedId" clearable filterable @change="handleChange">
	    <el-option
	      v-for="(item,index) in items"
	      :key="index"
	      :label="item.sz"
	      :value="item.sz"
		  >
	    </el-option>
	</el-select>
</template>
<script lang="ts">
import { defineComponent,onMounted,reactive, ref, toRefs} from 'vue'
import request from '/@/utils/request'

export default defineComponent({
    name: 'DictSelect',
    emits: ['dictSelected'],
    props: {
        lxid: Number,
        selectedId: String
    },
    setup(props, context) {
        const state = reactive({
            loading: false,
            items:[],
        })
        const loadData = ()=>{
            state.loading = true
			request.get('/system/dict/items/'+props.lxid).then(res => {
				state.items = res?.data || []
 			}).finally(()=>{
				state.loading = false
			})
        }
       
        onMounted(()=>{
            loadData();
        })
        const selectRef = ref();
        const handleChange = (data:any)=>{
            context.emit("dictSelected", data);
        }
        return {
            ...toRefs(state),
            ...toRefs(props),
            handleChange,
            selectRef,
        }
    }
})
</script>
